#ifndef _FIXEDPOINT_H_
#define _FIXEDPOINT_H_

#define FIX_TYPE				int32_t
#define FIX_FRACTION_LENGTH		8
#define FIX_MUL(x, y)			((FIX_TYPE) (x) * (y) >> FIX_FRACTION_LENGTH)
#define FIX_DIV(x, y)			(((FIX_TYPE) (x) <<  FIX_FRACTION_LENGTH) / (y))
#define FIX_FROM_INT(x)			((FIX_TYPE) (x) << FIX_FRACTION_LENGTH)
#define FIX_TO_INT(x)			((FIX_TYPE) (x) >> FIX_FRACTION_LENGTH)
#define FIX_TO_IPF(x, decimals)	FIX_TO_INT(x), ((decimals) * ((x) & ~(~((FIX_TYPE) 0) << FIX_FRACTION_LENGTH)) / (1 << FIX_FRACTION_LENGTH))

void getIntegerFraction(int32_t value, int decimals, int32_t *integer, int32_t *fraction);

#endif /* _FIXEDPOINT_H_ */
